package cn.jdw.shop.utils;

import lombok.Data;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

@Data
public class DateBody {
    private LocalDate oldDay;
    private LocalDate startDay;
    private LocalDate endDay;

    public void setStartDay(LocalDate startDay) {
        if (startDay == null || oldDay.until(startDay, ChronoUnit.DAYS) < 0) {
            this.startDay = oldDay.plusDays(-1);
        }else{
            this.startDay = startDay;
        }
    }

    private int money(long dayIndex) {
        if (dayIndex < 29) {
            return 0;
        } else if (dayIndex < 59) {
            return 25;
        } else if (dayIndex < 89) {
            return 50;
        } else {
            return 75;
        }
    }
    public int num1() {
        long b = startDay.until(endDay, ChronoUnit.DAYS);
        return (int) (b*75);
    }
    public int num2() {
        long a = oldDay.until(startDay, ChronoUnit.DAYS) + 1;
        long b = oldDay.until(endDay, ChronoUnit.DAYS) + 1;
        int sum = 0;
        for (long i = a; i < b; i++) {
            sum += money(i);
        }
        return sum;
    }
}



